package com.itheima;

public class HomeWork5 {
    public static void main(String[] args) {
        int[] arr = {1,2,3};
        System.out.println(convert(arr));
    }

    //如果传递的参数为空,返回null
    public static String convert(int[] arr) {
        if (arr == null) {
            return null;
        }
        //如果传递的元素个数为0,返回[]
        if (arr.length == 0) {
            return "[]";
        }
        // 如果数组int[] arr = {1,2,3};执行方法后输出的结果为:[1,2,3]
        String res = "[";
        for (int i = 0; i < arr.length; i++) {
            if (i != arr.length - 1) {
                res += arr[i];
                res += ",";
            }else{
                res += arr[i];
                res += "]";
            }
        }
        return res;

    }
}
